<!DOCTYPE html>
<html>
  
  <head>
    <meta charset="UTF-8">
    <title>房源模块</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="/backstage/css/font.css">
    <link rel="stylesheet" href="/backstage/css/xadmin.css">
      <link rel="stylesheet" href="/backstage/css/add_house.css?v=1">
      <style>
          .self-btn{
            margin-left:0;
          }

          .layui-form-label{
              width:150px !important;
          }

          .layui-input-block{margin-left:150px !important;}
      </style>

      <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  
  <body>
    <div class="x-body" id="main">
        <form action="" method="post" class="layui-form layui-form-pane">
                <div class="layui-form-item">
                    <label for="name" class="layui-form-label">
                        <span class="x-red">*</span>特色二手房
                    </label>

                    <div v-for="(item,index) in listData.resoldModule" class="layui-input-inline" style="margin-left:20px;border:2px solid #ccc">

                        <input type="button"   @click="showImgList(2,index)"  value="选择缩略图" class="self-btn" >
                        <img :src="imgPath+item.thumb_img" style="width:190px;" alt="">

                        <input type="text"  v-model="item.title" maxlength="10"  lay-verify="required"
                        autocomplete="off" class="layui-input" value="" placeholder="请输入标题">
                        <input type="text"  v-model="item.intro"  maxlength="10"  lay-verify="required"
                               autocomplete="off" class="layui-input"  placeholder="请输入副标题">
                    </div>

                </div>

            <div class="layui-form-item">
                <label for="name" class="layui-form-label">
                    <span class="x-red">*</span>优惠新盘
                </label>

                <div v-for="(item,index) in listData.newModule" class="layui-input-inline" style="margin-left:20px;border:2px solid #ccc">

                    <input type="button"   @click="showImgList(1,index)"  value="选择缩略图" class="self-btn" >
                    <img :src="imgPath+item.thumb_img" style="width:190px;" alt="">

                    <input type="text"  v-model="item.title" required="" lay-verify="required"
                           autocomplete="off" class="layui-input" value="" placeholder="请输入标题" maxlength="10">
                    <input type="text"  v-model="item.intro"  required="" lay-verify="required"
                           autocomplete="off" class="layui-input" value="" maxlength="10" placeholder="请输入副标题">
                </div>

            </div>



            <div class="layui-form-item" v-for="(item,index) in listData.modules">
                <label for="name" class="layui-form-label">
                    <span class="x-red">*</span>{{item.title}}<br/>

                </label>
                <div class="layui-input-inline">
                    <input type="button"   @click="showImgList(3,index)"  value="选择海报图" class="self-btn" >
                    <img :src="imgPath+item.poster_img" style="width:300px;" alt="">
                </div>
            </div>


             <div class="layui-form-item">
                <button class="layui-btn" lay-submit="" lay-filter="add" type="button">提交修改</button>
              </div>

            </form>
    </div>
  </body>

  <script type="text/javascript" src="/js/jquery.js"></script>
  <script type="text/javascript" src="/js/vue.js"></script>
  <script type="text/javascript" src="/backstage/lib/layui/layui.js" charset="utf-8"></script>
  <script type="text/javascript" src="/backstage/js/xadmin.js"></script>
  <script>
      layui.use(['form','layer'], function(){
          $ = layui.jquery;
        var form = layui.form
        ,layer = layui.layer;
      
        //监听提交
        form.on('submit(add)', function(data){

          $.post('',app.listData,function(res){
              if(res.code=='200'){
//                    // 获得frame索引
//                   var index = parent.layer.getFrameIndex(window.name);
//                      //关闭当前frame
//                   parent.layer.close(index);
                   parent.layer.msg("修改成功", {icon: 6,time:1000});

                   document.location.reload();

              }else{
                  layer.msg(res.msg, {icon: 5,time:1000});
              }
 
          },'json');
   
        });

      });


      //获取选择的图片
      var app = new Vue({
          el:'#main',
          data: {
              imgPath:'{:config("api.oss_img_path")}',
              type:0,
              index:0,
              returnImg:'',
              listData:{}

          },
          methods:{

              getListData:function(){
                  var that = this;
                  $.get('','',function(res){

                      that.listData = res;
                  },'json');


              },
              //处理从图片弹层传递过来的图片
              getImg:function(){

                  switch (this.type){
                      case 1:
                          this.listData.newModule[this.index].thumb_img = this.returnImg;
                          break;
                      case 2:
                          this.listData.resoldModule[this.index].thumb_img = this.returnImg;
                          break;
                      case 3:
                          this.listData.modules[this.index].poster_img = this.returnImg;
                          break;
                  }

              },


              //弹出图片选择列表
              showImgList:function(type,index){
                  this.type  = type;
                  this.index = index;
                  x_admin_show('选择图片','{:config(\'template.root_path\')}/resource/image_folder'+'?sel='+1);
              }



          },
          created: function () {
            this.getListData();
          }
      });

  </script>

</html>